import { defineStore } from 'pinia'
import type { User } from '@/types/user'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'cp-user',
  () => {
    // 1.用户信息状态
    const user = ref<User>()
    // 2.设置用户信息的函数
    const setUser = (users: User) => {
      user.value = users
    }
    // 3.删除用户信息的函数
    const deleteUser = () => {
      user.value = undefined
    }

    return { user, setUser, deleteUser }
  },
  {
    persist: true
  }
)
